Skip to content

Ability to set the DefineConstraints of packages#733

Open
kochounoyume wants to merge 7 commits intoGlitchEnzo:masterfrom
kochounoyume:master
Open

Ability to set the DefineConstraints of packages#733
kochounoyume wants to merge 7 commits intoGlitchEnzo:masterfrom
kochounoyume:master

Conversation

@kochounoyume
Copy link
Copy Markdown

@kochounoyume kochounoyume commented Oct 16, 2025

This is the implementation of feature #639 .

Enabling the DefineConstraints setting allows you to, for example, set restrictions on UNITY_EDITOR definitions for specific packages and exclude them from the build output.

This proves extremely useful within the Unity environment.

Refer to the existing implementation; #507

Comment thread src/NuGetForUnity/Editor/Configuration/PackageConfig.cs Outdated
Co-authored-by: JoC0de <53140583+JoC0de@users.noreply.github.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for configuring Unity PluginImporter Define Constraints per NuGet package via packages.config, enabling conditional referencing based on scripting define symbols (feature #639, similar to #507’s autoReferenced support).

Changes:

  • Parse and persist a new defineConstraints attribute in packages.config.
  • Apply defineConstraints to imported package DLLs via NugetAssetPostprocessor.
  • Document the new defineConstraints setting in the README.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/NuGetForUnity/Editor/NugetAssetPostprocessor.cs Applies package-level define constraints to Unity plugin importer settings.
src/NuGetForUnity/Editor/Configuration/PackagesConfigFile.cs Loads/saves defineConstraints from/to packages.config.
src/NuGetForUnity/Editor/Configuration/PackageConfig.cs Adds DefineConstraints property to package config model.
README.md Documents how to use defineConstraints in packages.config.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +295 to +298
if (!string.IsNullOrWhiteSpace(packageConfig.DefineConstraints))
{
plugin.DefineConstraints = packageConfig.DefineConstraints.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
}
Copy link
Copy Markdown
Collaborator

@JoC0de JoC0de Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point two options:

  1. We accept this behaviour so user can manually set DefineConstraints in the unity settings (if he commits the .meta file to git) even when he doesn't use the setting in package-config. But unfortunately this will lead to the behaviour that a if a user uses the setting and later removes it from package.config it will not be applied.
  2. We use the suggestion from Copilot -> a user that has set DefineConstraints in the .meta manually needs to mirror the setting to the package.config

Comment thread src/NuGetForUnity/Editor/Configuration/PackagesConfigFile.cs Outdated
Comment thread src/NuGetForUnity/Editor/Configuration/PackagesConfigFile.cs
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants